﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.CharacterDevelopment;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Roster;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x02000309 RID: 777
	public class HeadmanNeedsToDeliverAHerdIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002D2E RID: 11566 RVA: 0x000BD237 File Offset: 0x000BB437
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002D2F RID: 11567 RVA: 0x000BD250 File Offset: 0x000BB450
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x06002D30 RID: 11568 RVA: 0x000BD254 File Offset: 0x000BB454
		public void OnCheckForIssue(Hero hero)
		{
			if (this.ConditionsHold(hero))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnSelected), typeof(HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue), IssueBase.IssueFrequency.VeryCommon, null));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002D31 RID: 11569 RVA: 0x000BD2B8 File Offset: 0x000BB4B8
		private bool ConditionsHold(Hero issueGiver)
		{
			return issueGiver.CurrentSettlement != null && issueGiver.CurrentSettlement.IsVillage && HeadmanNeedsToDeliverAHerdIssueBehavior.IsVillageSuitableForIssue(issueGiver.CurrentSettlement.Village) && (issueGiver.IsHeadman || issueGiver.IsRuralNotable) && issueGiver.CurrentSettlement.Village.Bound.Notables.Count > 0 && issueGiver.CurrentSettlement.Village.Bound.Town.Security <= 60f;
		}

		// Token: 0x06002D32 RID: 11570 RVA: 0x000BD340 File Offset: 0x000BB540
		private static bool IsVillageSuitableForIssue(Village village)
		{
			return !village.Bound.IsCastle && (village.VillageType == DefaultVillageTypes.BattanianHorseRanch || village.VillageType == DefaultVillageTypes.DesertHorseRanch || village.VillageType == DefaultVillageTypes.EuropeHorseRanch || village.VillageType == DefaultVillageTypes.SteppeHorseRanch || village.VillageType == DefaultVillageTypes.SturgianHorseRanch || village.VillageType == DefaultVillageTypes.VlandianHorseRanch || village.VillageType == DefaultVillageTypes.CattleRange || village.VillageType == DefaultVillageTypes.SheepFarm || village.VillageType == DefaultVillageTypes.HogFarm);
		}

		// Token: 0x06002D33 RID: 11571 RVA: 0x000BD3D3 File Offset: 0x000BB5D3
		private IssueBase OnSelected(in PotentialIssueData pid, Hero issueOwner)
		{
			this._headmanNeedsToDeliverAHerdIssue = new HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue(issueOwner);
			return this._headmanNeedsToDeliverAHerdIssue;
		}

		// Token: 0x04000D8A RID: 3466
		private const IssueBase.IssueFrequency HeadmanNeedsToDeliverAHerdIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x04000D8B RID: 3467
		[SaveableField(216)]
		private HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue _headmanNeedsToDeliverAHerdIssue;

		// Token: 0x0200062D RID: 1581
		public class HeadmanNeedsToDeliverAHerdIssue : IssueBase
		{
			// Token: 0x06004CB9 RID: 19641 RVA: 0x0016044C File Offset: 0x0015E64C
			internal static void AutoGeneratedStaticCollectObjectsHeadmanNeedsToDeliverAHerdIssue(object o, List<object> collectedObjects)
			{
				((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004CBA RID: 19642 RVA: 0x0016045A File Offset: 0x0015E65A
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
				collectedObjects.Add(this._targetHero);
				collectedObjects.Add(this._herdTypeToDeliver);
			}

			// Token: 0x06004CBB RID: 19643 RVA: 0x00160487 File Offset: 0x0015E687
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue)o)._targetSettlement;
			}

			// Token: 0x06004CBC RID: 19644 RVA: 0x00160494 File Offset: 0x0015E694
			internal static object AutoGeneratedGetMemberValue_targetHero(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue)o)._targetHero;
			}

			// Token: 0x06004CBD RID: 19645 RVA: 0x001604A1 File Offset: 0x0015E6A1
			internal static object AutoGeneratedGetMemberValue_herdTypeToDeliver(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue)o)._herdTypeToDeliver;
			}

			// Token: 0x17000F9C RID: 3996
			// (get) Token: 0x06004CBE RID: 19646 RVA: 0x001604AE File Offset: 0x0015E6AE
			public override IssueBase.AlternativeSolutionScaleFlag AlternativeSolutionScaleFlags
			{
				get
				{
					return IssueBase.AlternativeSolutionScaleFlag.Duration;
				}
			}

			// Token: 0x17000F9D RID: 3997
			// (get) Token: 0x06004CBF RID: 19647 RVA: 0x001604B1 File Offset: 0x0015E6B1
			private int AnimalCountToDeliver
			{
				get
				{
					return (int)MathF.Clamp((float)MathF.Round(5000f * base.IssueDifficultyMultiplier / (float)this._herdTypeToDeliver.Value), 10f, 75f);
				}
			}

			// Token: 0x17000F9E RID: 3998
			// (get) Token: 0x06004CC0 RID: 19648 RVA: 0x001604E2 File Offset: 0x0015E6E2
			public override int AlternativeSolutionBaseNeededMenCount
			{
				get
				{
					return 6 + MathF.Ceiling(14f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000F9F RID: 3999
			// (get) Token: 0x06004CC1 RID: 19649 RVA: 0x001604F7 File Offset: 0x0015E6F7
			protected override int AlternativeSolutionBaseDurationInDaysInternal
			{
				get
				{
					return 5 + MathF.Ceiling(5f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000FA0 RID: 4000
			// (get) Token: 0x06004CC2 RID: 19650 RVA: 0x0016050C File Offset: 0x0015E70C
			protected override int RewardGold
			{
				get
				{
					return 300 + (int)((float)this._herdTypeToDeliver.Value * 0.75f * (float)this.AnimalCountToDeliver);
				}
			}

			// Token: 0x17000FA1 RID: 4001
			// (get) Token: 0x06004CC3 RID: 19651 RVA: 0x0016052F File Offset: 0x0015E72F
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=kDIi3bLN}The village needs someone to take a herd to {TARGET_SETTLEMENT}.", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					return textObject;
				}
			}

			// Token: 0x17000FA2 RID: 4002
			// (get) Token: 0x06004CC4 RID: 19652 RVA: 0x00160554 File Offset: 0x0015E754
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=7H4HQNvF}Yes. Some of the families in this village need to raise a bit of money. [if:convo_calm_friendly][ib:normal2]They've put together a herd of {ANIMAL_COUNT_TO_DELIVER} {.%}{?ANIMAL_COUNT_TO_DELIVER > 1}{PLURAL(HERD_TYPE_TO_DELIVER)}{?}{HERD_TYPE_TO_DELIVER}{\\?}{.%} to sell in {TARGET_SETTLEMENT}, but with all the banditry on the roads, they can't drive it there on their own. We're not merchants or landowners. We can't afford any losses.", null);
					if (base.IssueOwner.CharacterObject.GetPersona() == DefaultTraits.PersonaCurt)
					{
						textObject = new TextObject("{=6kJ31qut}Yeah, well, some people here are a bit short of money these days. [if:convo_calm_friendly][ib:normal]They've put together a herd of {ANIMAL_COUNT_TO_DELIVER} {.%}{?ANIMAL_COUNT_TO_DELIVER > 1}{PLURAL(HERD_TYPE_TO_DELIVER)}{?}{HERD_TYPE_TO_DELIVER}{\\?}{.%} to sell in {TARGET_SETTLEMENT}. But they're poor folks. Not really fighters, and they can't afford to hire guards. If they go there by themselves they'd be sitting ducks for any bandits.", null);
					}
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("ANIMAL_COUNT_TO_DELIVER", this.AnimalCountToDeliver);
					textObject.SetTextVariable("HERD_TYPE_TO_DELIVER", this._herdTypeToDeliver.Name);
					return textObject;
				}
			}

			// Token: 0x17000FA3 RID: 4003
			// (get) Token: 0x06004CC5 RID: 19653 RVA: 0x001605D1 File Offset: 0x0015E7D1
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					return new TextObject("{=lmJYF6pQ}Tell me how I can help.", null);
				}
			}

			// Token: 0x17000FA4 RID: 4004
			// (get) Token: 0x06004CC6 RID: 19654 RVA: 0x001605E0 File Offset: 0x0015E7E0
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=VbRyXBsv}If you're going in the direction of {TARGET_SETTLEMENT}, you can perhaps take our herd there to {TARGET_HERO.LINK}. I am willing to pay {REWARD_AMOUNT}{GOLD_ICON} if you deliver them safe and sound.[if:convo_calm_friendly][ib:normal]", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("REWARD_AMOUNT", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FA5 RID: 4005
			// (get) Token: 0x06004CC7 RID: 19655 RVA: 0x0016064C File Offset: 0x0015E84C
			public override TextObject IssueAlternativeSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=CqmoyrHH}You can assign a companion with {REQUIRED_SOLDIERS} men, they will be enough too. Both ways works fine for us. I promise if you or your men manage to deliver the herd safely, I will pay you {REWARD}{GOLD_ICON}. So what do you say?[if:convo_nonchalant]", null);
					textObject.SetTextVariable("REQUIRED_SOLDIERS", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("REWARD", this.RewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000FA6 RID: 4006
			// (get) Token: 0x06004CC8 RID: 19656 RVA: 0x0016069C File Offset: 0x0015E89C
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=MJdVfS4z}Don't worry. I will deliver your {ANIMAL_COUNT_TO_DELIVER} {.%}{?ANIMAL_COUNT_TO_DELIVER > 1}{PLURAL(HERD_TYPE_TO_DELIVER)}{?}{HERD_TYPE_TO_DELIVER}{\\?}{.%} personally to {TARGET_HERO.LINK} in {TARGET_SETTLEMENT}.", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					textObject.SetTextVariable("ANIMAL_COUNT_TO_DELIVER", this.AnimalCountToDeliver);
					textObject.SetTextVariable("HERD_TYPE_TO_DELIVER", this._herdTypeToDeliver.Name);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FA7 RID: 4007
			// (get) Token: 0x06004CC9 RID: 19657 RVA: 0x00160710 File Offset: 0x0015E910
			public override TextObject IssueAlternativeSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=k8W02aj9}I will assign a companion with {NEEDED_MEN_COUNT} of my men to deliver {ANIMAL_COUNT_TO_DELIVER} {.%}{?ANIMAL_COUNT_TO_DELIVER > 1}{PLURAL(HERD_TYPE_TO_DELIVER)}{?}{HERD_TYPE_TO_DELIVER}{\\?}{.%} safely.", null);
					textObject.SetTextVariable("NEEDED_MEN_COUNT", base.GetTotalAlternativeSolutionNeededMenCount());
					textObject.SetTextVariable("ANIMAL_COUNT_TO_DELIVER", this.AnimalCountToDeliver);
					textObject.SetTextVariable("HERD_TYPE_TO_DELIVER", this._herdTypeToDeliver.Name);
					return textObject;
				}
			}

			// Token: 0x17000FA8 RID: 4008
			// (get) Token: 0x06004CCA RID: 19658 RVA: 0x00160763 File Offset: 0x0015E963
			public override TextObject IssueDiscussAlternativeSolution
			{
				get
				{
					TextObject textObject = new TextObject("{=mwpY5Ylb}I am still waiting for news from {TARGET_SETTLEMENT}. Once again, I appreciate that you could spare the men to do this.[if:convo_calm_friendly]", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000FA9 RID: 4009
			// (get) Token: 0x06004CCB RID: 19659 RVA: 0x00160788 File Offset: 0x0015E988
			public override TextObject IssueAlternativeSolutionResponseByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=BJxJwCc5}Thank you, {?PLAYER.GENDER}madam{?}sir{\\?}. Any brigands would be most unwise to tangle with you.", null);
					if (base.IssueOwner.CharacterObject.GetPersona() == DefaultTraits.PersonaCurt)
					{
						textObject = new TextObject("{=muE5fcOf}Good. Anyone gives you trouble... Well, you look like you could handle them.", null);
					}
					StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FAA RID: 4010
			// (get) Token: 0x06004CCC RID: 19660 RVA: 0x001607D8 File Offset: 0x0015E9D8
			protected override TextObject AlternativeSolutionStartLog
			{
				get
				{
					TextObject textObject = new TextObject("{=m2h6zMp7}{ISSUE_GIVER.LINK}, the headman from {SETTLEMENT}, has asked you to deliver some of the village's livestock to {SETTLEMENT_TARGET}. The villagers can't afford their own guards and also can't afford any losses. {ISSUE_GIVER.LINK} offers {REWARD_AMOUNT}{GOLD_ICON} for the herd's delivery. You sent {COMPANION.LINK} with {NEEDED_MEN_COUNT} of your men to protect the herd. They should return to you with news of their success in {RETURN_DAYS} days.", null);
					StringHelpers.SetCharacterProperties("ISSUE_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("COMPANION", base.AlternativeSolutionHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("SETTLEMENT", base.IssueOwner.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("SETTLEMENT_TARGET", this._targetSettlement.Name);
					textObject.SetTextVariable("NEEDED_MEN_COUNT", this.AlternativeSolutionSentTroops.TotalManCount - 1);
					textObject.SetTextVariable("RETURN_DAYS", base.GetTotalAlternativeSolutionDurationInDays());
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					textObject.SetTextVariable("REWARD_AMOUNT", this.RewardGold);
					return textObject;
				}
			}

			// Token: 0x17000FAB RID: 4011
			// (get) Token: 0x06004CCD RID: 19661 RVA: 0x001608A3 File Offset: 0x0015EAA3
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return true;
				}
			}

			// Token: 0x17000FAC RID: 4012
			// (get) Token: 0x06004CCE RID: 19662 RVA: 0x001608A6 File Offset: 0x0015EAA6
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000FAD RID: 4013
			// (get) Token: 0x06004CCF RID: 19663 RVA: 0x001608AC File Offset: 0x0015EAAC
			public override TextObject IssueAsRumorInSettlement
			{
				get
				{
					TextObject textObject = new TextObject("{=cvZH3cI1}I hope {QUEST_GIVER.NAME} has a plan to get that herd to market.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FAE RID: 4014
			// (get) Token: 0x06004CD0 RID: 19664 RVA: 0x001608DE File Offset: 0x0015EADE
			protected override int CompanionSkillRewardXP
			{
				get
				{
					return (int)(500f + 700f * base.IssueDifficultyMultiplier);
				}
			}

			// Token: 0x17000FAF RID: 4015
			// (get) Token: 0x06004CD1 RID: 19665 RVA: 0x001608F3 File Offset: 0x0015EAF3
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=KhUkmIrH}Deliver the herd to {TARGET_SETTLEMENT}", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x06004CD2 RID: 19666 RVA: 0x00160918 File Offset: 0x0015EB18
			public HeadmanNeedsToDeliverAHerdIssue(Hero issueOwner) : base(issueOwner, CampaignTime.DaysFromNow(30f))
			{
				HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue <>4__this = this;
				Settlement settlement = SettlementHelper.FindRandomSettlement(delegate(Settlement x)
				{
					if (x.IsTown)
					{
						float num;
						if (x.Notables.Any((Hero y) => y.CanHaveQuestsOrIssues()) && !x.MapFaction.IsAtWarWith(issueOwner.MapFaction) && !Campaign.Current.Models.MapDistanceModel.GetDistance(x, <>4__this.IssueSettlement, 100f, out num))
						{
							return Campaign.Current.Models.MapDistanceModel.GetDistance(x, <>4__this.IssueSettlement, 250f, out num);
						}
					}
					return false;
				});
				this._targetSettlement = (settlement ?? base.IssueSettlement.Village.Bound);
				this._herdTypeToDeliver = Campaign.Current.ObjectManager.GetObject<ItemObject>(this._possibleHerdTypes.GetRandomElement<string>());
				if (this._targetSettlement != null)
				{
					this._targetHero = (this._targetSettlement.Notables.GetRandomElementWithPredicate((Hero x) => x.CanHaveQuestsOrIssues()) ?? this._targetSettlement.Notables.GetRandomElement<Hero>());
				}
			}

			// Token: 0x06004CD3 RID: 19667 RVA: 0x00160A19 File Offset: 0x0015EC19
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.SettlementProsperity)
				{
					return -0.2f;
				}
				return 0f;
			}

			// Token: 0x06004CD4 RID: 19668 RVA: 0x00160A2E File Offset: 0x0015EC2E
			public override ValueTuple<SkillObject, int> GetAlternativeSolutionSkill(Hero hero)
			{
				return new ValueTuple<SkillObject, int>((hero.GetSkillValue(DefaultSkills.Riding) >= hero.GetSkillValue(DefaultSkills.Scouting)) ? DefaultSkills.Riding : DefaultSkills.Scouting, 120);
			}

			// Token: 0x06004CD5 RID: 19669 RVA: 0x00160A5B File Offset: 0x0015EC5B
			public override bool DoTroopsSatisfyAlternativeSolution(TroopRoster troopRoster, out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(troopRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x06004CD6 RID: 19670 RVA: 0x00160A73 File Offset: 0x0015EC73
			public override bool IsTroopTypeNeededByAlternativeSolution(CharacterObject character)
			{
				return character.Tier >= 2;
			}

			// Token: 0x06004CD7 RID: 19671 RVA: 0x00160A84 File Offset: 0x0015EC84
			public override bool IssueStayAliveConditions()
			{
				return !base.IssueOwner.CurrentSettlement.IsRaided && !base.IssueOwner.CurrentSettlement.IsUnderRaid && this._targetHero.IsActive && base.IssueOwner.CurrentSettlement.Village.Bound.Town.Security <= 70f;
			}

			// Token: 0x06004CD8 RID: 19672 RVA: 0x00160AED File Offset: 0x0015ECED
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x06004CD9 RID: 19673 RVA: 0x00160AEF File Offset: 0x0015ECEF
			public override bool AlternativeSolutionCondition(out TextObject explanation)
			{
				explanation = TextObject.Empty;
				return QuestHelper.CheckRosterForAlternativeSolution(MobileParty.MainParty.MemberRoster, base.GetTotalAlternativeSolutionNeededMenCount(), ref explanation, 2, false);
			}

			// Token: 0x06004CDA RID: 19674 RVA: 0x00160B10 File Offset: 0x0015ED10
			protected override void AlternativeSolutionEndWithSuccessConsequence()
			{
				this.ApplySuccessRewards(base.IssueOwner);
			}

			// Token: 0x06004CDB RID: 19675 RVA: 0x00160B1E File Offset: 0x0015ED1E
			private void ApplySuccessRewards(Hero issueGiver)
			{
				issueGiver.AddPower(5f);
				this.RelationshipChangeWithIssueOwner = 5;
				issueGiver.CurrentSettlement.Village.Hearth += 50f;
			}

			// Token: 0x06004CDC RID: 19676 RVA: 0x00160B4E File Offset: 0x0015ED4E
			protected override void OnGameLoad()
			{
			}

			// Token: 0x06004CDD RID: 19677 RVA: 0x00160B50 File Offset: 0x0015ED50
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004CDE RID: 19678 RVA: 0x00160B52 File Offset: 0x0015ED52
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest(questId, base.IssueOwner, CampaignTime.DaysFromNow(30f), this.AnimalCountToDeliver, this._herdTypeToDeliver, this._targetSettlement, this.RewardGold, this._targetHero);
			}

			// Token: 0x06004CDF RID: 19679 RVA: 0x00160B88 File Offset: 0x0015ED88
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x06004CE0 RID: 19680 RVA: 0x00160B8C File Offset: 0x0015ED8C
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flag, out Hero relationHero, out SkillObject skill)
			{
				flag = IssueBase.PreconditionFlags.None;
				relationHero = null;
				skill = null;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flag |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (issueGiver.CurrentSettlement.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flag |= IssueBase.PreconditionFlags.AtWar;
				}
				return flag == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x040019DD RID: 6621
			private const float MaxDistanceForSettlementSelection = 250f;

			// Token: 0x040019DE RID: 6622
			private const float MinDistanceForSettlementSelection = 100f;

			// Token: 0x040019DF RID: 6623
			private const int IssueDuration = 30;

			// Token: 0x040019E0 RID: 6624
			private const int QuestTimeLimit = 30;

			// Token: 0x040019E1 RID: 6625
			private const int AlternativeSolutionTroopTierRequirement = 2;

			// Token: 0x040019E2 RID: 6626
			private const int RequiredSkillForSendingCompanion = 120;

			// Token: 0x040019E3 RID: 6627
			[CachedData]
			private readonly MBList<string> _possibleHerdTypes = new MBList<string>
			{
				"sheep",
				"cow",
				"hog"
			};

			// Token: 0x040019E4 RID: 6628
			[SaveableField(10)]
			private Settlement _targetSettlement;

			// Token: 0x040019E5 RID: 6629
			[SaveableField(20)]
			private Hero _targetHero;

			// Token: 0x040019E6 RID: 6630
			[SaveableField(30)]
			private ItemObject _herdTypeToDeliver;
		}

		// Token: 0x0200062E RID: 1582
		public class HeadmanNeedsToDeliverAHerdIssueQuest : QuestBase
		{
			// Token: 0x06004CE1 RID: 19681 RVA: 0x00160BE1 File Offset: 0x0015EDE1
			internal static void AutoGeneratedStaticCollectObjectsHeadmanNeedsToDeliverAHerdIssueQuest(object o, List<object> collectedObjects)
			{
				((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x06004CE2 RID: 19682 RVA: 0x00160BEF File Offset: 0x0015EDEF
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
				collectedObjects.Add(this._targetHero);
				collectedObjects.Add(this._herdTypeToDeliver);
				collectedObjects.Add(this._playerStartsQuestLog);
			}

			// Token: 0x06004CE3 RID: 19683 RVA: 0x00160C28 File Offset: 0x0015EE28
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o)._targetSettlement;
			}

			// Token: 0x06004CE4 RID: 19684 RVA: 0x00160C35 File Offset: 0x0015EE35
			internal static object AutoGeneratedGetMemberValue_targetHero(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o)._targetHero;
			}

			// Token: 0x06004CE5 RID: 19685 RVA: 0x00160C42 File Offset: 0x0015EE42
			internal static object AutoGeneratedGetMemberValue_herdTypeToDeliver(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o)._herdTypeToDeliver;
			}

			// Token: 0x06004CE6 RID: 19686 RVA: 0x00160C4F File Offset: 0x0015EE4F
			internal static object AutoGeneratedGetMemberValue_animalCountToDeliver(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o)._animalCountToDeliver;
			}

			// Token: 0x06004CE7 RID: 19687 RVA: 0x00160C61 File Offset: 0x0015EE61
			internal static object AutoGeneratedGetMemberValue_rewardGold(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o)._rewardGold;
			}

			// Token: 0x06004CE8 RID: 19688 RVA: 0x00160C73 File Offset: 0x0015EE73
			internal static object AutoGeneratedGetMemberValue_playerStartsQuestLog(object o)
			{
				return ((HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest)o)._playerStartsQuestLog;
			}

			// Token: 0x17000FB0 RID: 4016
			// (get) Token: 0x06004CE9 RID: 19689 RVA: 0x00160C80 File Offset: 0x0015EE80
			public sealed override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=KhUkmIrH}Deliver the herd to {TARGET_SETTLEMENT}", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x17000FB1 RID: 4017
			// (get) Token: 0x06004CEA RID: 19690 RVA: 0x00160CA4 File Offset: 0x0015EEA4
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x17000FB2 RID: 4018
			// (get) Token: 0x06004CEB RID: 19691 RVA: 0x00160CA8 File Offset: 0x0015EEA8
			private TextObject _playerStartsQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=wsGDDXPN}{QUEST_GIVER.LINK}, the headman from {QUEST_GIVER_SETTLEMENT} has asked you to deliver {ANIMAL_COUNT_TO_DELIVER} {.%}{?ANIMAL_COUNT_TO_DELIVER > 1}{PLURAL(HERD_TYPE_TO_DELIVER)}{?}{HERD_TYPE_TO_DELIVER}{\\?}{.%} to {TARGET_HERO.LINK} in {TARGET_SETTLEMENT}. {?QUEST_GIVER.GENDER}She{?}He{\\?} fears such a large herd will attract attention from the brigands on the way. {QUEST_GIVER.LINK} offers {REWARD_AMOUNT}{GOLD_ICON} for the herd's delivery.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("TARGET_HERO", this._targetHero.CharacterObject, textObject, false);
					textObject.SetTextVariable("QUEST_GIVER_SETTLEMENT", base.QuestGiver.CurrentSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("ANIMAL_COUNT_TO_DELIVER", this._animalCountToDeliver);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.EncyclopediaLinkWithName);
					textObject.SetTextVariable("HERD_TYPE_TO_DELIVER", this._herdTypeToDeliver.Name);
					textObject.SetTextVariable("REWARD_AMOUNT", this._rewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000FB3 RID: 4019
			// (get) Token: 0x06004CEC RID: 19692 RVA: 0x00160D74 File Offset: 0x0015EF74
			private TextObject _successQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=6IKKFH3A}You have received a message and a large purse from {QUEST_GIVER.LINK}. The missive reads: ”The herd is safe. Thank you, and please accept these {REWARD}{GOLD_ICON} with our gratitude.”.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("REWARD", this._rewardGold);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000FB4 RID: 4020
			// (get) Token: 0x06004CED RID: 19693 RVA: 0x00160DCC File Offset: 0x0015EFCC
			private TextObject _failByTimeOutQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=hhrRnSvr}You failed to deliver the herd in time, as {QUEST_GIVER.LINK} has asked of you. The shepherds and the herd left you.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000FB5 RID: 4021
			// (get) Token: 0x06004CEE RID: 19694 RVA: 0x00160E10 File Offset: 0x0015F010
			private TextObject _failByRejectQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=MjwNHtQd}You rejected to deliver the herd, as {QUEST_GIVER.LINK} has asked of you. The shepherds have left you.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("GOLD_ICON", "{=!}<img src=\"General\\Icons\\Coin@2x\" extend=\"8\">");
					return textObject;
				}
			}

			// Token: 0x17000FB6 RID: 4022
			// (get) Token: 0x06004CEF RID: 19695 RVA: 0x00160E54 File Offset: 0x0015F054
			private TextObject _questCanceledWarDeclaredLog
			{
				get
				{
					TextObject textObject = new TextObject("{=vW6kBki9}Your clan is now at war with {QUEST_GIVER.LINK}'s realm. Your agreement with {QUEST_GIVER.LINK} is canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x17000FB7 RID: 4023
			// (get) Token: 0x06004CF0 RID: 19696 RVA: 0x00160E88 File Offset: 0x0015F088
			private TextObject _playerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x06004CF1 RID: 19697 RVA: 0x00160EBC File Offset: 0x0015F0BC
			public HeadmanNeedsToDeliverAHerdIssueQuest(string questId, Hero questGiver, CampaignTime duration, int animalCountToDeliver, ItemObject herdTypeToDeliver, Settlement targetSettlement, int rewardGold, Hero targetHero) : base(questId, questGiver, duration, rewardGold)
			{
				this._animalCountToDeliver = animalCountToDeliver;
				this._herdTypeToDeliver = herdTypeToDeliver;
				this._targetSettlement = targetSettlement;
				this._rewardGold = rewardGold;
				this._targetHero = targetHero;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x06004CF2 RID: 19698 RVA: 0x00160F08 File Offset: 0x0015F108
			protected override void SetDialogs()
			{
				TextObject textObject = new TextObject("{=iUQuwAZY}Thank you, {?PLAYER.GENDER}madam{?}sir{\\?}. The village will be grateful to you. Good luck.", null);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject, false);
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(textObject, null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(new TextObject("{=zB6elkn1}The herd is ready to depart.", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).BeginPlayerOptions().PlayerOption(new TextObject("{=8tBET7S5}Good. We will be heading out soon.", null), null).NpcLine(new TextObject("{=iAGx49nO}Good to hear that! Safe journeys.[if:convo_approving]", null), null, null).CloseDialog().PlayerOption(new TextObject("{=EOaOlh39}In due time. Let's not be too hasty.", null), null).NpcLine(new TextObject("{=79Te4duG}As you wish.[if:convo_normal][ib:demure]", null), null, null).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06004CF3 RID: 19699 RVA: 0x00161008 File Offset: 0x0015F208
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				this._playerStartsQuestLog = base.AddLog(this._playerStartsQuestLogText, false);
				this.AddHerdAndShepherdsToMainParty();
				base.AddTrackedObject(this._targetSettlement);
				base.AddTrackedObject(this._targetHero);
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetDeliveryDialogFlow(), this);
			}

			// Token: 0x06004CF4 RID: 19700 RVA: 0x00161064 File Offset: 0x0015F264
			protected override void OnCompleteWithSuccess()
			{
				base.QuestGiver.AddPower(5f);
				this.RelationshipChangeWithQuestGiver = 5;
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, 30)
				});
				base.QuestGiver.CurrentSettlement.Village.Hearth += 50f;
				this._targetSettlement.Town.Prosperity += 50f;
				int availableRequestedItemCountOnPlayer = this.GetAvailableRequestedItemCountOnPlayer(this._herdTypeToDeliver);
				int num = (availableRequestedItemCountOnPlayer > this._animalCountToDeliver) ? this._animalCountToDeliver : availableRequestedItemCountOnPlayer;
				foreach (ItemRosterElement itemRosterElement in MobileParty.MainParty.ItemRoster)
				{
					if (itemRosterElement.EquipmentElement.Item == this._herdTypeToDeliver)
					{
						int amount = itemRosterElement.Amount;
						if (amount >= num)
						{
							PartyBase.MainParty.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, -num);
							this._targetSettlement.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, num);
							break;
						}
						num -= amount;
						PartyBase.MainParty.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, -amount);
						this._targetSettlement.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, amount);
					}
				}
				GiveGoldAction.ApplyForQuestBetweenCharacters(base.QuestGiver, Hero.MainHero, this._rewardGold, false);
				base.AddLog(this._successQuestLogText, false);
			}

			// Token: 0x06004CF5 RID: 19701 RVA: 0x00161204 File Offset: 0x0015F404
			protected override void OnFinalize()
			{
				base.RemoveTrackedObject(this._targetSettlement);
				base.RemoveTrackedObject(this._targetHero);
			}

			// Token: 0x06004CF6 RID: 19702 RVA: 0x00161220 File Offset: 0x0015F420
			private DialogFlow GetDeliveryDialogFlow()
			{
				TextObject textObject = new TextObject("{=8nwZXNTk}About the task {QUEST_GIVER.LINK} gave me...", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
				TextObject textObject2 = new TextObject("{=kwJBLl00}Yes {?PLAYER.GENDER}madam{?}sir{\\?}. Our mutual friend {QUEST_GIVER.LINK} sent word to us. {?QUEST_GIVER.GENDER}She{?}He{\\?} told us to expect you with {?QUEST_GIVER.GENDER}her{?}his{\\?} {HERD_AMOUNT} {.%}{?HERD_AMOUNT > 1}{PLURAL(HERD_TYPE)}{?}{HERD_TYPE}{\\?}{.%}.", null);
				TextObject npcText = new TextObject("{=vXCg3OYx}So, have you brought them?[if:convo_undecided_open]", null);
				textObject2.SetTextVariable("HERD_AMOUNT", this._animalCountToDeliver);
				textObject2.SetTextVariable("HERD_TYPE", this._herdTypeToDeliver.Name);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject2, false);
				StringHelpers.SetCharacterProperties("PLAYER", CharacterObject.PlayerCharacter, textObject2, false);
				TextObject textObject3 = new TextObject("{=wmZYHGb9}I brought {HERD_AMOUNT} {.%}{?HERD_AMOUNT > 1}{PLURAL(HERD_TYPE)}{?}{HERD_TYPE}{\\?}{.%} as we agreed.", null);
				textObject3.SetTextVariable("HERD_AMOUNT", this._animalCountToDeliver);
				textObject3.SetTextVariable("HERD_TYPE", this._herdTypeToDeliver.Name);
				TextObject textObject4 = new TextObject("{=VkUMPAfR}Thank you for your help. {QUEST_GIVER.LINK} will send your reward as soon as possible.[if:convo_calm_friendly][ib:demure]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject4, false);
				TextObject text = new TextObject("{=1s54uxsA}Sorry. I don't have any animals for you this time.", null);
				TextObject npcText2 = new TextObject("{=1dUVrgQ8}I just hope you can deliver the herd soon.", null);
				TextObject text2 = new TextObject("{=HFZisEnI}I'm going to keep that herd for myself.", null);
				TextObject textObject5 = new TextObject("{=LpfQYLQo}What? That's straight-up theft. I guarantee you {QUEST_GIVER.LINK} will hear about this![if:convo_annoyed][ib:aggressive]", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject5, false);
				return DialogFlow.CreateDialogFlow("hero_main_options", 125).PlayerLine(textObject, null).Condition(() => Settlement.CurrentSettlement == this._targetSettlement && CharacterObject.OneToOneConversationCharacter.IsHero && CharacterObject.OneToOneConversationCharacter.HeroObject == this._targetHero).NpcLine(textObject2, null, null).NpcLine(npcText, null, null).BeginPlayerOptions().PlayerOption(textObject3, null).Condition(delegate
				{
					int availableRequestedItemCountOnPlayer = this.GetAvailableRequestedItemCountOnPlayer(this._herdTypeToDeliver);
					Campaign.Current.ConversationManager.GetCurrentDialogLine().SetTextVariable("HERD_AMOUNT", this._animalCountToDeliver);
					Campaign.Current.ConversationManager.GetCurrentDialogLine().SetTextVariable("HERD_TYPE", this._herdTypeToDeliver.Name);
					return availableRequestedItemCountOnPlayer >= this._animalCountToDeliver;
				}).NpcLine(textObject4, null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.DeliverHerdOnConsequence)).CloseDialog().PlayerOption(text2, null).NpcLine(textObject5, null, null).Consequence(new ConversationSentence.OnConsequenceDelegate(this.DeliverHerdRejectOnConsequence)).CloseDialog().PlayerOption(text, null).NpcLine(npcText2, null, null).CloseDialog().EndPlayerOptions().CloseDialog();
			}

			// Token: 0x06004CF7 RID: 19703 RVA: 0x0016141B File Offset: 0x0015F61B
			private void DeliverHerdRejectOnConsequence()
			{
				ChangeCrimeRatingAction.Apply(base.QuestGiver.CurrentSettlement.MapFaction, 20f, true);
				base.CompleteQuestWithFail(null);
			}

			// Token: 0x06004CF8 RID: 19704 RVA: 0x0016143F File Offset: 0x0015F63F
			private void DeliverHerdOnConsequence()
			{
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x06004CF9 RID: 19705 RVA: 0x00161448 File Offset: 0x0015F648
			private int GetAvailableRequestedItemCountOnPlayer(ItemObject item)
			{
				int num = 0;
				foreach (ItemRosterElement itemRosterElement in PartyBase.MainParty.ItemRoster)
				{
					if (itemRosterElement.EquipmentElement.Item == item)
					{
						num += itemRosterElement.Amount;
					}
				}
				return num;
			}

			// Token: 0x06004CFA RID: 19706 RVA: 0x001614B4 File Offset: 0x0015F6B4
			public override void OnCanceled()
			{
				int availableRequestedItemCountOnPlayer = this.GetAvailableRequestedItemCountOnPlayer(this._herdTypeToDeliver);
				PartyBase.MainParty.ItemRoster.AddToCounts(this._herdTypeToDeliver, (availableRequestedItemCountOnPlayer > this._animalCountToDeliver) ? (-this._animalCountToDeliver) : (-availableRequestedItemCountOnPlayer));
			}

			// Token: 0x06004CFB RID: 19707 RVA: 0x001614F8 File Offset: 0x0015F6F8
			protected override void OnTimedOut()
			{
				this.ApplyFailureEffects(true);
				base.AddLog(this._failByTimeOutQuestLogText, false);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -10)
				});
				this.RemoveRemainingHorses();
			}

			// Token: 0x06004CFC RID: 19708 RVA: 0x00161535 File Offset: 0x0015F735
			public override void OnFailed()
			{
				this.ApplyFailureEffects(false);
				base.AddLog(this._failByRejectQuestLogText, false);
				TraitLevelingHelper.OnIssueSolvedThroughQuest(base.QuestGiver, new Tuple<TraitObject, int>[]
				{
					new Tuple<TraitObject, int>(DefaultTraits.Honor, -30)
				});
			}

			// Token: 0x06004CFD RID: 19709 RVA: 0x0016156C File Offset: 0x0015F76C
			private void ApplyFailureEffects(bool isTimedOut = false)
			{
				base.QuestGiver.AddPower(-5f);
				this._targetSettlement.Town.Prosperity -= 10f;
				this.RelationshipChangeWithQuestGiver = (isTimedOut ? -5 : -10);
			}

			// Token: 0x06004CFE RID: 19710 RVA: 0x001615AC File Offset: 0x0015F7AC
			private void RemoveRemainingHorses()
			{
				int num = this._animalCountToDeliver;
				foreach (ItemRosterElement itemRosterElement in MobileParty.MainParty.ItemRoster)
				{
					if (itemRosterElement.EquipmentElement.Item == this._herdTypeToDeliver)
					{
						int amount = itemRosterElement.Amount;
						if (amount >= num)
						{
							PartyBase.MainParty.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, -num);
							break;
						}
						num -= amount;
						PartyBase.MainParty.ItemRoster.AddToCounts(itemRosterElement.EquipmentElement, -amount);
					}
				}
			}

			// Token: 0x06004CFF RID: 19711 RVA: 0x00161660 File Offset: 0x0015F860
			private void AddHerdAndShepherdsToMainParty()
			{
				MobileParty.MainParty.ItemRoster.AddToCounts(this._herdTypeToDeliver, this._animalCountToDeliver);
				MobileParty.MainParty.ItemRoster.AddToCounts(DefaultItems.Grain, 5);
				TextObject textObject = new TextObject("{=GgBtpOEm}{.%}{ANIMAL_COUNT} {?ANIMAL_COUNT > 1}{PLURAL(ANIMAL_TYPE)}{?}{ANIMAL_TYPE}{\\?}{.%} added to your party.", null);
				textObject.SetTextVariable("ANIMAL_COUNT", this._animalCountToDeliver);
				textObject.SetTextVariable("ANIMAL_TYPE", this._herdTypeToDeliver.Name);
				MBInformationManager.AddQuickInformation(textObject, 0, null, "");
			}

			// Token: 0x06004D00 RID: 19712 RVA: 0x001616DF File Offset: 0x0015F8DF
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
				Campaign.Current.ConversationManager.AddDialogFlow(this.GetDeliveryDialogFlow(), this);
			}

			// Token: 0x06004D01 RID: 19713 RVA: 0x001616FD File Offset: 0x0015F8FD
			protected override void HourlyTick()
			{
			}

			// Token: 0x06004D02 RID: 19714 RVA: 0x00161700 File Offset: 0x0015F900
			protected override void RegisterEvents()
			{
				CampaignEvents.HeroKilledEvent.AddNonSerializedListener(this, new Action<Hero, Hero, KillCharacterAction.KillCharacterActionDetail, bool>(this.OnHeroKilled));
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
			}

			// Token: 0x06004D03 RID: 19715 RVA: 0x00161769 File Offset: 0x0015F969
			public override void OnHeroCanHaveQuestOrIssueInfoIsRequested(Hero hero, ref bool result)
			{
				if (hero == this._targetHero)
				{
					result = false;
				}
			}

			// Token: 0x06004D04 RID: 19716 RVA: 0x00161777 File Offset: 0x0015F977
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x17000FB8 RID: 4024
			// (get) Token: 0x06004D05 RID: 19717 RVA: 0x0016178A File Offset: 0x0015F98A
			protected override TextObject TargetHeroDiedLogText
			{
				get
				{
					return new TextObject("{=m41vdhSR}{QUEST_TARGET.LINK} is no longer alive. It might not be your fault that you didn't get the herd to {?QUEST_TARGET.GENDER}her{?}him{\\?} in time, but many people will consider this breach of trust.", null);
				}
			}

			// Token: 0x06004D06 RID: 19718 RVA: 0x00161798 File Offset: 0x0015F998
			private void OnHeroKilled(Hero victim, Hero killer, KillCharacterAction.KillCharacterActionDetail detail, bool showNotification)
			{
				if (victim == this._targetHero)
				{
					TextObject textObject = (detail == KillCharacterAction.KillCharacterActionDetail.Lost) ? this.TargetHeroDisappearedLogText : this.TargetHeroDiedLogText;
					StringHelpers.SetCharacterProperties("QUEST_TARGET", this._targetHero.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					base.AddLog(textObject, false);
					base.CompleteQuestWithCancel(null);
				}
			}

			// Token: 0x06004D07 RID: 19719 RVA: 0x00161801 File Offset: 0x0015FA01
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (base.QuestGiver.CurrentSettlement.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					base.CompleteQuestWithCancel(this._questCanceledWarDeclaredLog);
				}
			}

			// Token: 0x06004D08 RID: 19720 RVA: 0x00161830 File Offset: 0x0015FA30
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this._playerDeclaredWarQuestLogText, this._questCanceledWarDeclaredLog, false);
			}

			// Token: 0x040019E7 RID: 6631
			[SaveableField(10)]
			private readonly Settlement _targetSettlement;

			// Token: 0x040019E8 RID: 6632
			[SaveableField(20)]
			private readonly Hero _targetHero;

			// Token: 0x040019E9 RID: 6633
			[SaveableField(30)]
			private readonly ItemObject _herdTypeToDeliver;

			// Token: 0x040019EA RID: 6634
			[SaveableField(40)]
			private readonly int _animalCountToDeliver;

			// Token: 0x040019EB RID: 6635
			[SaveableField(70)]
			private int _rewardGold;

			// Token: 0x040019EC RID: 6636
			[SaveableField(215)]
			private JournalLog _playerStartsQuestLog;
		}

		// Token: 0x0200062F RID: 1583
		public class HeadmanNeedsToDeliverAHerdIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06004D0D RID: 19725 RVA: 0x00161901 File Offset: 0x0015FB01
			public HeadmanNeedsToDeliverAHerdIssueTypeDefiner() : base(430000)
			{
			}

			// Token: 0x06004D0E RID: 19726 RVA: 0x0016190E File Offset: 0x0015FB0E
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssue), 1, null);
				base.AddClassDefinition(typeof(HeadmanNeedsToDeliverAHerdIssueBehavior.HeadmanNeedsToDeliverAHerdIssueQuest), 2, null);
			}
		}
	}
}
